package com.zhang.modules.auth.controller;


import com.zhang.common.web.respWrapper.Res;
import com.zhang.modules.api.annotation.ApiPermission;
import com.zhang.modules.auth.eneity.Role;
import com.zhang.modules.auth.eneity.cmd.AddRoleDto;
import com.zhang.modules.auth.eneity.dto.RoleDto;
import com.zhang.modules.auth.service.IRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Api(tags = "系统角色管理")
@RequestMapping("/api/sysRole")
@ApiPermission("sys:role:*")
public class RoleController {

    private IRoleService roleService;

    public RoleController(IRoleService roleService) {
        this.roleService = roleService;
    }

    @ApiOperation("系统角色列表")
    @ApiPermission("sys:role:list")
    @GetMapping("/page")
    public Res<Page<RoleDto>> page(Role role, HttpServletRequest request){
        Page<RoleDto> result = roleService.page(role, request.getParameterMap());
        return Res.ok(result);
    }


    @ApiOperation("添加系统角色")
    @ApiPermission("sys:role:add")
    @PostMapping("/add")
    public Res add(AddRoleDto role){
        roleService.add(role);
        return Res.ok();
    }

    @ApiOperation("编辑系统角色")
    @ApiPermission("sys:role:edit")
    @PostMapping("/edit")
    public Res edit(AddRoleDto role){
        roleService.edit(role);
        return Res.ok();
    }


    @ApiOperation("添加系统角色")
    @ApiPermission("sys:role:delete")
    @GetMapping("/delete")
    public Res edit(String id){
        roleService.deleteLogic(id);
        return Res.ok();
    }


}
